package CloudStorage;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class Utility
{
    public static String getDate()
    {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date = new java.util.Date();
        return dateFormat.format(date);
    }

    public static int getDaysRegistered( User user )
    {
        int yearRegistered, year;
        int monthRegistered, month;
        int dayRegistered, day;

        String dateString = getDate();

        yearRegistered = Integer.parseInt(user.getLastLogin().substring(0, 4));
        year = Integer.parseInt(dateString.substring(0, 4));

        monthRegistered = Integer.parseInt(user.getLastLogin().substring(5, 7));
        month = Integer.parseInt(dateString.toString().substring(5, 7));

        dayRegistered = Integer.parseInt(user.getLastLogin().substring(8, 10));
        day = Integer.parseInt(dateString.substring(8, 10));

        return ( year - yearRegistered ) * 365 + ( month - monthRegistered ) * 30 + day - dayRegistered;
    }

    public static String getPostFix(String string)
    {
        int index;
        for ( index = string.length() - 1; index > 0; index-- )
        {
            if ( string.charAt(index) == '.' )
            {
                break;
            }
        }

        return string.substring(index + 1);
    }

    public static String getPrefix(String string)
    {
        int index;
        for ( index = 0; index < string.length(); index++ )
        {
            if ( string.charAt(index) == '.' )
            {
                break;
            }
        }

        return string.substring(0, index);
    }

    public static float computeCharge(float space)
    {

            if ( space < 10 )
            {
                return space * 15;
            }
            else if ( space > 10 && space < 100 )
            {
                return 10 * 15 + ( space - 10 ) * 20;
            }
            else
            {
                return 10 * 15 + 90 * 20 + ( space - 100 ) * 25;
            }
    }
}
